import dataList from "@/components/dataList";
import messageSend from "../component/message-sending";
import { rentPropertyPage, rentPropertyDelete } from "../api/rentalProperty.js";
import { sendMsg } from "~/views/message-center/message-list/api/message";
import BaseLoad from "@/assets/vue-mixin/BaseLoad";
export default {
    name: "rentalProperty",
    mixins: [BaseLoad],
    components: { dataList, messageSend },
    provide() {
        return {
            initList: this.getListData
        };
    },
    beforeMount() {
        this.getListData();
    },
    data() {
        return {
            tableData: [],
            // 请求参数
            params: {
                current: 1,
                size: 20,
                projectName: ""
            },
            // 选中的数据
            selectionList: [],
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 20 // 每页显示多少条
            },
            // 页面loading
            loading: false,
            filterList: [
                {
                    label: "管理权属",
                    inputType: "dict",
                    dictName: "administrative_office",
                    name: "manageUnit",
                    multiple: true
                }
            ]
        };
    },
    methods: {
        // hxf-1015-分页请求
        getListData(params = {}) {
            this.loading = true;
            let requestData = { ...this.params, ...params };
            rentPropertyPage(requestData)
                .then(res => {
                    const { current, size, total, records } = res.data.data;
                    this.tableData = records;
                    this.params = requestData;
                    this.pager = { total, current, size };
                })
                .finally(() => {
                    this.loading = false;
                });
        },
        // hxf-1015-多选选中
        selectionChange(val) {
            this.selectionList = val;
        },
        // hxf-1015-新增
        handleRentalPropertyAdd() {
            this.$router.push({ name: "rental_add" });
        },
        // hxf-1015-编辑
        handleRentalPropertyEdit(row) {
            this.$router.push({
                name: "rental_edit",
                query: { projectId: row.projectId }
            });
        },
        // hxf-1015-查看
        handleRentalPropertyLook(row) {
            this.$router.push({
                name: "rental_look",
                query: { projectId: row.projectId }
            });
        },
        // hxf-1015-打开消息发送
        handleOpenMessageSend() {
            this.$refs.messageSend.show();
        },
        // hxf-1015-执行消息发送
        handleDoMessageSend(data) {
            this.loadAction("保存中");
            sendMsg(data)
                .then(res => {
                    this.loadClose();
                    this.$message.success("保存成功！");
                })
                .catch(e => {
                    console.log(e);
                    this.loadClose();
                    this.$message.error("保存失败！");
                });
        },
        //hxf-1016-删除
        handleDelete() {
            if (this.selectionList.length === 0) {
                this.$alert("请勾选要删除的数据！");
                return;
            }
            let ids = this.selectionList.map(sd => sd.projectId);
            this.$confirm("此操作将永久删除该数据, 是否继续?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    rentPropertyDelete(ids)
                        .then(rep => {
                            this.$message.success("删除成功");
                            this.resetList();
                        })
                        .catch(e => {
                            this.$message.error("删除失败");
                        });
                })
                .catch(() => {
                    this.$message.info("已取消删除");
                });
        },
        // 菜单点击监听
        handleMenuClick(type) {
            switch (type) {
                case "add":
                    this.handleRentalPropertyAdd();
                    break;
                case "test":
                    this.handleOpenMessageSend();
                    break;
                case "delete":
                    this.handleDelete();
                    break;
                default:
                    this.$message(type);
                    break;
            }
        }
    }
};
